import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author LiuYan
 * @date 2023/5/15
 */
public class TeeingCollector {

    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);

        // 计算数字的总和和平均值
        Result result = numbers.stream()
                .collect(Collectors.teeing(
                        Collectors.summingInt(Integer::intValue),
                        Collectors.averagingInt(Integer::intValue),
                        (sum, avg) -> new Result(sum, avg)));
        System.out.println("总和：" + result.sum);
        System.out.println("平均值：" + result.avg);
    }

    private static class Result {
        int sum;
        double avg;

        public Result(int sum, double avg) {
            this.sum = sum;
            this.avg = avg;
        }
    }
}
